From 6ee2028996ee9d8802201e95f3cec56e2b307ddb Mon Sep 17 00:00:00 2001
From: Jean-Louis Dupond <jean-louis@dupond.be>
Date: Sat, 5 May 2012 16:54:18 +0200
Subject: [PATCH] Fix crashes in some cases

---
 remmina-plugins/rdp/rdp_cliprdr.c |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/remmina-plugins/rdp/rdp_cliprdr.c b/remmina-plugins/rdp/rdp_cliprdr.c
index d84374e..772709c 100644
--- a/remmina-plugins/rdp/rdp_cliprdr.c
+++ b/remmina-plugins/rdp/rdp_cliprdr.c
@@ -204,7 +204,7 @@ uint8* remmina_rdp_cliprdr_get_data(RemminaProtocolWidget* gp, uint32 format, in
 	g_printf("GetData: Requested Format: %#X\n", format);
 	rfContext* rfi = GET_DATA(gp);
 	GtkClipboard* clipboard;
-	uint8* inbuf = (uint8*)"";
+	uint8* inbuf = NULL;
 	uint8* outbuf = NULL;
 	GdkPixbuf *image = NULL;
 	
@@ -223,10 +223,18 @@ uint8* remmina_rdp_cliprdr_get_data(RemminaProtocolWidget* gp, uint32 format, in
 	}
 	THREADS_LEAVE
 
+	/* No data received, send nothing */
+	if (inbuf == NULL && image == NULL)
+	{
+		g_printf("NO DATA RECEIVED\n");
+		*size = 0;
+		return NULL;
+	}
+
+
 	if (format == CB_FORMAT_TEXT || format == CB_FORMAT_HTML || format == CB_FORMAT_UNICODETEXT)
 	{
-		if (inbuf == NULL)
-			inbuf = (uint8*)"";
+		*size = strlen((char*)inbuf);
 		inbuf = lf2crlf(inbuf, size);
 		if (format == CB_FORMAT_TEXT)
 		{
@@ -258,12 +266,14 @@ uint8* remmina_rdp_cliprdr_get_data(RemminaProtocolWidget* gp, uint32 format, in
 			gdk_pixbuf_save_to_buffer(image, &data, &buffersize, "png", NULL, NULL);
 			outbuf = (uint8*) xmalloc(buffersize);
 			memcpy(outbuf, data, buffersize);
+			*size = buffersize;
 		}
 		if (format == CB_FORMAT_JPEG)
 		{
 			gdk_pixbuf_save_to_buffer(image, &data, &buffersize, "jpeg", NULL, NULL);
 			outbuf = (uint8*) xmalloc(buffersize);
 			memcpy(outbuf, data, buffersize);
+			*size = buffersize;
 		}
 		if (format == CB_FORMAT_DIB)
 		{
@@ -276,9 +286,6 @@ uint8* remmina_rdp_cliprdr_get_data(RemminaProtocolWidget* gp, uint32 format, in
 		g_object_unref(image);
 	}
 
-	if (!outbuf)
-		outbuf = (uint8*)"";
-
 	return outbuf;
 }
 
-- 
1.7.10

